﻿using Microsoft.Phone.Data.Linq.Mapping;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace depl
{

    public class Entry : INotifyPropertyChanged, IComparable<Entry>
    {

        public int _isInFavourites = -1;
        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        public bool IsInFavourites
        {
            get
            {
                if (_isInFavourites == -1)
                    return EntryStorage.Instance.ContainsName(this.Name);//need to check by name because "Favourites" contain different references after initialization from file
                else if (_isInFavourites == 1)
                    return true;
                return false;
            }
            set
            {
                if (value)
                    _isInFavourites = 1;
                else
                    _isInFavourites = 0;
                NotifyPropertyChanged();
            }
        }

        public string Name { get; set; }

        public string NormalizedName { get; set; }

        public string Content { get; set; }

        public string NormalizedContent { get; set; }

        public bool IsReversed { get; set; }

        public List<string> RelatedEntryNames = new List<string>();

        /*public override string ToString()
        {
            return Name;
        }*/

        public int CompareTo(Entry compareEntry)
        {
            return Name.CompareTo(compareEntry.Name);
        }
    }
}
